package com.czh.convert;

import com.czh.entity.User;
import com.czh.vo.UserVO;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

/**
 * user类型转换
 *
 * @author chenzhihua
 * @Date 2024/7/24
 */
@Mapper(unmappedSourcePolicy = ReportingPolicy.IGNORE, builder = @Builder(disableBuilder = true))
public interface UserConvert {
    UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);

    @Mappings({})
    UserVO do2vo(User user);

    /**
     * vo其它值进行赋值
     *
     * @param user
     * @return
     */
    @Mapping(target = "idName", expression = "java(getIdName(user.getId()))")
    UserVO do2vodemo(User user);


    default String getIdName(Long id) {
        if (id < 10) {
            return "小于10";
        } else {
            return "大于10";
        }
    }
}
